﻿using ITXHWEB.Models;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Data;
using WPFExcelReport.Helpers;
namespace ITXHWEB.Controllers
{
    public partial class WBBSTController
    {
        public ActionResult MGEBNR(string returnUrl)
        {
            ModelState.Clear();
            MABF.CWBB.REMARK = MABF.CWBB.GEBNR + "盘;" + 0 + "卷;" + 0 + "米;"+INFO;
            if (MABF.CWBB.GEBNR != "")
            { 
                if (MABF.CWBB.IsGEBNRReady)
                {
                    dwData = VHP.VWBB.TBMain.NewRow();
                    dwData["WBBMANDANT"] = app.Mandant;
                    dwData["WBBGEBNR"] = MABF.CWBB.GEBNR.PadRight(8);

                    SResult = VHP.VWBB.QWBGEBNRSP(dwData);
                    DataTable tb = SResult.Tables[0].Copy();
                    int pcs = 0;
                    double mtrs = 0;
                    foreach (DataRow _dwWB in tb.Rows)
                    {
                        pcs++;
                        mtrs += double.Parse(_dwWB["WBBISTKLG"].ToString());
                        MABF.ART = _dwWB["WBBART"].ToString();
                        MABF.CWBB.VAR = _dwWB["WBBVAR"].ToString();
                        MABF.CWBB.FARBE = _dwWB["WBBFARBE"].ToString(); 
                    } 
                    MABF.CWBB.REMARK = MABF.CWBB.GEBNR + "盘;" + pcs + "卷;" + Helper.RoundX(mtrs, 1) + "米;"+INFO;
                }
            }
            ViewBag.ReturnUrl = returnUrl;
            return PartialView(MABF.CWBB);
        }

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult MGEBNR(List<WBBSTModel> m, string returnUrl)
        {
            ModelState.Clear();
            MABF = new ABFOLGEModel();
            MABF.CWBB.IsGEBNRReady = false;
            MABF.IsPDCReady = false;
            MABF.IsVVTReady = false;
            MABF.IsVKPReady = false;
            return RedirectToAction(MAPP, MAPP);
        }
    }
}
